package org.cms.call;

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

/**
 * Created by elnoa on 28/10/14.
 */
public class GetUserInfoCall extends AbstractCall<HttpGet> {

        public GetUserInfoCall(HttpClient httpclient, String access_token) {
            super(httpclient,access_token);
        }

        public GetUserInfoCall invoke() {
            URI getCalendarListUrl = null;
            try {
                getCalendarListUrl = new URIBuilder()
                        .setScheme("https")
                        .setHost("www.googleapis.com")
                        .setPath("/oauth2/v2/userinfo")
                        .setParameter("access_token", getAccess_token())
                        .build();

            setRequest(new HttpGet(getCalendarListUrl));
            System.out.println("executing request to " + getRequest());
            setResponse(getHttpclient().execute(getRequest()));

            } catch (IOException e) {
                e.printStackTrace();
            }catch (URISyntaxException e) {
                e.printStackTrace();
            }
            return this;
        }
    }